package com.changdu.seatunnel.admin.pojo;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonIgnore;

import lombok.Data;

@Data
public class ShowTaskTables {
	
	@JsonIgnore
	public static final List<String> MYSQL = Arrays.asList("-", "数据库", "表名");
	@JsonIgnore
	public static final List<String> SINK_KAFKA = Arrays.asList("匹配规则", "主题", "分区");
	@JsonIgnore
	public static final List<String> SOURCE_KAFKA = Arrays.asList("主题", "数据库", "表");
	
	private List<String> sourceHeaders;
	
	private List<TaskTable> sourceTables = new LinkedList<>();
	
	private List<String> sinkHeaders;

	private List<TaskTable> sinkTables = new LinkedList<>();
	
	@Data
	static class TaskTable {
		
		private String pattern;
		
		private String database;
		
		private String table;
		
	}

	public void addSourceTable(String pattern, String dbName, String dbTable) {
		sourceTables.add(buildTaskTable(pattern, dbName, dbTable));
	}

	private TaskTable buildTaskTable(String pattern, String dbName, String dbTable) {
		TaskTable table = new TaskTable();
		table.setPattern(pattern);
		table.setDatabase(dbName);
		table.setTable(dbTable);
		return table;
	}
	
	public void addSinkTable(String pattern, String dbName, String dbTable) {
		sinkTables.add(buildTaskTable(pattern, dbName, dbTable));
	}
	
	public void addSourceHeader(List<String> sourceHeaders) {
		this.sourceHeaders = sourceHeaders;
	}
	
	public void addSinkHeader(List<String> sinkHeaders) {
		this.sinkHeaders = sinkHeaders;
	}	
	
} 